doctype html
html
	head
		meta(charset="utf-8")
		meta(name="renderer" content="webkit")
		meta(http-equiv="Access-Control-Allow-Origin" content="*")
		meta(http-equiv="X-UA-Compatible" content="IE=EmulateIE11")
		meta(name="viewport" content="width=device-width, initial-scale=1.0")
		meta(name="description" content="标识汇")
		meta(name="keyword" content="标识汇")
		title 标识汇-注册
		link(href="${relativePath}/static/css/common.css" type="text/css" rel="stylesheet")
		link(href="${relativePath}/static/css/login.css" type="text/css" rel="stylesheet")
	body
		div.layout.login-container
			//- 头部
			header
				div.logo.fl
					img(src="${relativePath}/static/imgs/logo.png")
					i
					span 新用户注册
				div.right-nav.fr
					ul
						li
							a.phonecall(href="#") 热线电话：400-100-2848
		//- banner
		div.banner.registBox
			div.registInner
				div.topReg
					span.newreg 新用户注册
					span.alLogin.fr
						| 已有账号，
						| <a href="login.html">请登陆</a>
				div.registBt
					div.haveNum
						label.hasNum.active 有邀请码
						label.noNum 无邀请码
					form.logBox.login-box#regist
						div.fl_wrap
							input.real_name(type="text" name="name" placeholder="请输入姓名")
						div.fl_wrap
							input.nice_name(type="text" name="nice_name" placeholder="邀请码")
						div.fl_wrap
							input.phone_num(type="text" name="phone_num" placeholder="请输入手机号")
						div.fl_wrap
							input.message_num(type="text" name="message_num" placeholder="请输入短信验证码")
							input(type="button" value="获取验证码").num_code#sendBtn
						div.fl_wrap
							input.password#password(type="password" name="password" placeholder="设置密码" required="true")
						div.fl_wrap
							input.password_pre(name="password_pre" type="password" placeholder="确认密码" required="true")
						span.agree
							label
								input.agreeMe(type="checkbox" name="agreeMe" required)
								| &nbsp;我已阅读并同意
								| <a href="javascript:;"> 《使用条款及协议》</a>
						a.regBtn(href="javascript:;") 注 册
					form.logBox.login-box#noregist
						div.fl_wrap
							input.real_name(type="text" name="name" placeholder="请输入姓名")
						div.fl_wrap
							input.phone_num(type="text" name="phone_num" placeholder="请输入手机号")
						div.fl_wrap
							input.message_num(type="text" autocomplete="off" name="message_num" placeholder="请输入短信验证码")
							input(type="button" value="获取验证码").num_code#sendBtnone
						div.fl_wrap
							input.message_num#yyzz(type="text" name="message_num" placeholder="")
							a.href#lastHref(href="javascript:;") 请点击选择营业执照
							input(type="button" value="点击上传").num_code.upone
							input#yyzzhide(type="hidden")
							input.photofile.yyzzFile#files(type="file"  name="files[]" multiple="")
							a.resource.resourceone(href="javascript:;") 参考
						div.fl_wrap
							input.message_num#sqs(type="text" name="message_num" placeholder="")
							a.href#lastHref2(href="javascript:;") 请点击选择授权书
							input(type="button" value="点击上传").num_code.uptwo
							input#sqshide(type="hidden")
							input.photofile.sqsFile#files_2(type="file"  name="files_2[]" multiple="")
							a.resource.download(href="javascript:;") 下载
							a.resource.resourcetwo(href="javascript:;") 参考
						div.fl_wrap
							input.password#passwordone(type="password" name="passwordone" placeholder="设置密码" required="true")
						div.fl_wrap
							input.password_pre(name="password_pre" type="password" placeholder="确认密码" required="true")
						span.agree
							label
								input.agreeMe(type="checkbox" name="agreeMe" required checked="checked" disabled)
								| &nbsp;我已阅读并同意
								| <a href="javascript:;"> 《使用条款及协议》</a>
						a.regBtn(href="javascript:;" allids="") 注 册
					div#yycard
						img(src="${relativePath}/static/imgs/yyzz.png")
					div#sqscard
						img(src="${relativePath}/static/imgs/sqs.png")
					//- form#test(enctype ="multipart/form-data")
					//- 	input#files(type="file"  name="files[]"  multiple="")
					//- 	input#files_2(type="file"  name="files_2[]"  multiple="")


		//- 底部
		div.footer
			div.footer-inner
				div.left
					p 标识汇官网|成品材料|定制加工|需求中心|社区资讯|工作ERP|办公OA微单系统|供销存
					p @copy;2015标识汇  豫ICP备15032515
					p 版权所有：标识汇网络技术有限公司
				div.code
					div.code_1
						img(src="${relativePath}/static/imgs/code_1.png")
						p 下载手机标识汇
					div.code_2
						img(src="${relativePath}/static/imgs/code_2.png")
						p 关注微信公众号

block pageScript
	script(type="text/javascript" src="${relativePath}/static/js/jquery.min.js")
	script(type="text/javascript" src="${relativePath}/static/js/libs/jquery.cookie.js")
	script(type="text/javascript" src="${relativePath}/static/js/common.js")
	script(type="text/javascript" src="${relativePath}/static/js/jquery.validate.min.js")
	script(type="text/javascript" src="${relativePath}/static/js/messages_zh.js")
	script(src="${relativePath}/static/js/libs/layer/layer.js")

	script.
		$(function(){
			var statu;
			$(".haveNum label").click(function() {
				$(this).addClass("active").siblings().removeClass("active");
				$(".registBt .logBox").hide().eq($(this).index()).show();
			})
			// 手机号码验证
			jQuery.validator.addMethod("isMobile", function(value, element) {
				var length = value.length;
				var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
				return this.optional(element) || (length == 11 && mobile.test(value));
			}, "请正确填写您的手机号码");
			//- 发送验证码
			var countdown=60;
			function settime(obj) {
			    if (countdown == 0) {
			        obj.removeAttribute("disabled");    
			        obj.value="获取验证码";
			        countdown = 60;
			        return;
			    } else {
			        obj.setAttribute("disabled", true);
			        obj.value="重新发送(" + countdown + ")";
			        countdown--;
			    }
			setTimeout(function() {
			    settime(obj) }
			    ,1000)
			}
			var validator = $("#regist").validate({
					rules: {
						nice_name:{
							required:true
						},
						recommender_num:{
							required : true,
							minlength : 11,
							// 自定义方法：校验手机号在数据库中是否存在
							// checkPhoneExist : true,
				    		isMobile : true
						},
						phone_num:{
							required:true,
							isMobile:true
						},
						message_num:{
							required:true,
						},
						password:{
							required: true
						},
						password_pre:{
							required: true,
							equalTo: "#password"
						}
					},
					messages : {
						nice_name:{
							required : "请输入邀请码"
						},
				        recommender_num : {
							required : "请输入推荐人号码"
				        },
				        phone_num:{
				        	required:'请输入手机号'
				        },
				        message_num:{
				        	required:'请输入验证码'
				        },
				        password:{
				        	required:'请输入密码',
				        	minlength: 8
				        },
				        password_pre:{
				        	required:'请确认密码',
				        	equalTo: "两次密码输入不一致"
				        }
				    },
				    errorPlacement: function(error, element) {  
					    error.appendTo(element.closest(".fl_wrap"));
						if(element.is("[name='agreeMe']")) {
							element.closest("span.agree").find("label.error").remove();
							element.closest("span.agree").append(error);
						}
					}
				});
			var validator2 = $("#noregist").validate({
					rules: {
						nice_name:{
							required:true
						},
						recommender_num:{
							required : true,
							minlength : 11,
							// 自定义方法：校验手机号在数据库中是否存在
							// checkPhoneExist : true,
				    		isMobile : true
						},
						phone_num:{
							required:true,
							isMobile:true
						},
						message_num:{
							required:true,
						},
						password:{
							required: true
						},
						password_pre:{
							required: true,
							equalTo: "#passwordone"
						}
					},
					messages : {
						nice_name:{
							required : "请输入邀请码"
						},
				        recommender_num : {
							required : "请输入推荐人号码"
				        },
				        phone_num:{
				        	required:'请输入手机号'
				        },
				        message_num:{
				        	required:'请输入验证码'
				        },
				        password:{
				        	required:'请输入密码',
				        	minlength: 8
				        },
				        password_pre:{
				        	required:'请确认密码',
				        	equalTo: "两次密码输入不一致"
				        }
				    },
				    errorPlacement: function(error, element) {  
					    error.appendTo(element.closest(".fl_wrap"));
						if(element.is("[name='agreeMe']")) {
							element.closest("span.agree").find("label.error").remove();
							element.closest("span.agree").append(error);
						}
					}
				});
			//- 点击发送验证码
			$("#sendBtn").click(function(){
				var phoneNum = $("#regist .phone_num").val();
				var _this = this;
				if(phoneNum == ""){
					layer.msg("请先输入手机号")
				}else{
					$.ajax({
						url:shopIp+"/Utils/sendCaptcha",
						type:"post",
						data:{
							os:"web",
							phone:phoneNum,
							register:1
						},
						dataType: "jsonp",
					}).done(function(data){
						if(data.status == "200"){
							layer.msg(data.msg);
							settime(_this);
						}else{
							layer.msg(data.msg);
						}
					})
				}
			})
			$("#sendBtnone").click(function(){
				var phoneNum = $("#noregist .phone_num").val();
				var _this = this;
				if(phoneNum == ""){
					layer.msg("请先输入手机号")
				}else{
					$.ajax({
						url:shopIp+"/Utils/sendCaptcha",
						type:"post",
						data:{
							os:"web",
							phone:phoneNum,
							register:1
						},
						dataType: "jsonp",
					}).done(function(data){
						if(data.status == "200"){
							layer.msg(data.msg);
							settime(_this);
						}else{
							layer.msg(data.msg);
						}
					})
				}
				
			})

			//- 点击注册
			
			$("#regist .regBtn").click(function(){
				var nice_name = $("#regist .nice_name").val();
				var real_name = $("#regist .real_name").val();
				var phoneNum = $("#regist .phone_num").val();
				var message_num = $("#regist .message_num").val();
				var password = $("#regist .password").val();
				var password_pre = $("#regist .password_pre").val();
				if(validator.form()) {
					//验证通过
					$.ajax({
						url:shopIp+"/Account/register",
						data:{
							os:"web",
							nice_name:real_name,
							phone:phoneNum,
							inviterPhone:nice_name,
							smsCode:message_num,
							password:password,
							repassword:password_pre,
						},
						dataType: "jsonp",
					}).done(function(data){
						//console.log(data);
						if(data.status == "200"){
							window.location.href = "login.html";
						}else{
							layer.msg(data.msg);
						}
					})
				}
			})
			$("#regist .phone_num").blur(function() {
				var $this = $("this");
				$.get(commonIp+'/unified/checkPhoneIsExists?phone='+$("#regist .phone_num").val(),function(data) {
					if(data.data.code == "1" || data.data.code == "2") {
						layer.msg(data.data.msg);
					} else if(data.data.code == "3") {
						layer.msg(data.data.msg);
					} else if(data.data.code == "0"){
						layer.msg(data.data.msg);
					}
				})
			})
			$("#noregist .phone_num").blur(function() {
				var $this = $("this");
				$.get(commonIp+'/unified/checkPhoneIsExists?phone='+$("#noregist .phone_num").val()+'&type=2',function(data) {
					if(data.data.code == "1" || data.data.code == "2") {
						layer.msg(data.data.msg)
					} else if(data.data.code == "3") {
						$("#noregist .regBtn").html("修改");
						$("#noregist .regBtn").css("background","#ccc");
						$("#noregist .regBtn").attr("allids",data.data.id);
						statu=2;
					} else if(data.data.code == "0"){
						statu=1;
						$("#noregist .regBtn").html("注册");
						$("#noregist .regBtn").css("background","#ffc001");
					}
				})
			})
			$("#noregist .regBtn").click(function(){
				var nice_name = $("#noregist .nice_name").val();
				var real_name = $("#noregist .real_name").val();
				var phoneNum = $("#noregist .phone_num").val();
				var message_num = $("#noregist .message_num").val();
				var certificate = $("#sqshide").val();
				var licence = $("#yyzzhide").val();
				var password = $("#noregist .password").val();
				var password_pre = $("#noregist .password_pre").val();
				if(statu == 2) {
					$.ajax({
						url:shopIp+"/account/updateRegisterSelf",
						data:{
							os:"web",
							phone:phoneNum,
							nice_name:real_name,
							id:$("#noregist .regBtn").attr("allids"),
							smsCode:message_num,
							password:password,
							licence:licence,
							certificate:certificate,
							repassword:password_pre,
						},
						dataType: "jsonp",
					}).done(function(data){
						if(data.status == "200"){
							window.location.href = "login.html";
						}else{
							layer.msg(data.msg);
						}
					})
				}else{
					$.ajax({
						url:shopIp+"/account/registerSelf",
						data:{
							os:"web",
							phone:phoneNum,
							nice_name:real_name,
							smsCode:message_num,
							password:password,
							licence:licence,
							certificate:certificate,
							repassword:password_pre,
						},
						dataType: "jsonp",
					}).done(function(data){
						if(data.status == "200"){
							window.location.href = "login.html";
						}else{
							layer.msg(data.msg);
						}
					})
				}
			})
			//- 点击下载
			$.get(commonIp+'/unified/download',function(data){
				//console.log(data);
				$(".download").attr("href",data.data);
			})
			//- 点击参考营业执照
			$(".resourceone").click(function() {
				layer.open({
				  type: 1,
				  title: false,
				  closeBtn: 1,
				  area: '884px',
				  skin: 'layui-layer-nobg', //没有背景色
				  shadeClose: true,
				  content: $('#yycard')
				});
			})
			//- 点击参考营业执照
			$(".resourcetwo").click(function() {
				layer.open({
				  type: 1,
				  title: false,
				  closeBtn: 1,
				  area: '790px',
				  skin: 'layui-layer-nobg', //没有背景色
				  shadeClose: true,
				  content: $('#sqscard')
				});
			})
			//- 上传y营业执照及授权书
			if (window.File && window.FileReader && window.FileList && window.Blob){
				//Blob是计算机界通用术语之一，全称写作：BLOB (binary large object)，表示二进制大对象。
				//全部支持
				function handleFileSelect(evt) {
					var files = evt.target.files, f = files[0];
					var formdata=new FormData($("#noregist")[0]);
					//console.log(formdata)
					if (!/image\/\w+/.test(f.type)){
						layer.msg("请确保文件为图像类型");
						return false;
					}
					var reader = new FileReader();
					reader.onload = (function(theFile) {
						return function(e) {
							
						};
					})(f);
					reader.readAsDataURL(f);
					$.ajax({
						url:shopIp+"/Utils/uploadFiles?userToken="+token,
						type:"post",
						data:formdata,
						dataType:"json",
						async:false,
						cache:false,
						contentType:false,
						processData:false,
						success:function(data) {
							$("#lastHref").html("")
							$("#lastHref").html(data.data.url);
							$("#lastHref").attr({
								"href":data.data.url,
								"target":"_blank"
							});
							$("#lastHref").css("color","#6794c6")
							$("#yyzzhide").val(data.data.path);
						},
						error:function(data) {
							console.log(data);
						}
					})
				}
				function handleFileSelect2(evt) {
					var files_2 = evt.target.files, f = files_2[0];
					var formdata=new FormData($("#noregist")[0])
					if (!/image\/\w+/.test(f.type)){
						layer.msg("请确保文件为图像类型");
						return false;
					}
					var reader = new FileReader();
					reader.onload = (function(theFile) {
						return function(e) {
							
						};
					})(f);
					reader.readAsDataURL(f);
					$.ajax({
						url:shopIp+"/Utils/uploadFiles?userToken="+token,
						type:"post",
						data:formdata,
						dataType:"json",
						async:false,
						cache:false,
						contentType:false,
						processData:false,
						success:function(data) {
							$("#lastHref2").html("")
							$("#lastHref2").html(data.data.url);
							$("#lastHref2").attr({
								"href":data.data.url,
								"target":"_blank"
							});
							$("#lastHref2").css("color","#6794c6")
							$("#sqshide").val(data.data.path);
						},
						error:function(data) {
							console.log(data);
						}
					})

				}
				document.getElementById('files_2').addEventListener('change', handleFileSelect2, false);
				document.getElementById('files').addEventListener('change', handleFileSelect, false);

			}else {
			    layer.msg('该浏览器不全部支持File APIs的功能');
			}
		})






